package {
	
  import flash.display.Graphics;
  import flash.display.Sprite;
  import flash.events.Event;
  import flash.media.Sound;
  import flash.media.SoundChannel;
  import flash.media.SoundMixer;
  import flash.net.URLRequest;
  import flash.utils.ByteArray;
[SWF(width='1024', height='768', backgroundColor='#ffffff', frameRate='30')]
    public class WOCA extends Sprite {

        public function WOCA() {
            var snd:Sound = new Sound();
            var req:URLRequest = new URLRequest("1.mp3");
            snd.load(req);
            
            var channel:SoundChannel;
            channel = snd.play();
            addEventListener(Event.ENTER_FRAME, onEnterFrame);
            channel.addEventListener(Event.SOUND_COMPLETE, onPlaybackComplete);
        }
		private var dddd:int = 0;
		
		private var or:Number = 0;
		
        private function onEnterFrame(event:Event):void {
        	dddd++;
        	
        	
        	
            var bytes:ByteArray = new ByteArray();
            const PLOT_HEIGHT:int = 200;
            const CHANNEL_LENGTH:int = 256;

            SoundMixer.computeSpectrum(bytes, true, 0);
            
            var g:Graphics = this.graphics;
            
            g.clear();
       
            g.lineStyle(1, 0x6600CC);
            g.beginFill(0x6600CC);
            g.moveTo(0, PLOT_HEIGHT);
            
            var n:Number = 0;
            var max:Number = 0;
            var t:Number = 0;
            for (var i:int = 0; i < CHANNEL_LENGTH; i++) {
            	//if(i%10 ==1){
	                n = (bytes.readFloat() * PLOT_HEIGHT);
	                
	                if(n > max){
	                	max = n;
	                }
	                t = t +n;
	                
	                g.moveTo(i * 2, PLOT_HEIGHT);
	                g.lineTo(i * 2, PLOT_HEIGHT - n);
            	// }
            }
			var ss:int = (t/256 + max) / 2;
			 
			
			
			 
			 g.lineStyle(8, 0x000000);
			 g.moveTo(600, PLOT_HEIGHT);
			 g.lineTo(600, PLOT_HEIGHT - ss);
             g.endFill();
 	
 			if(dddd%3 != 0)
        	 return;
        	 trace(ss - or);
			 if(ss - or > 10){
			 	new Something().addMe(this);
			 }
           	or = ss;
        }
        
        private function onPlaybackComplete(event:Event):void {
            removeEventListener(Event.ENTER_FRAME, onEnterFrame);
        }
    }
}
